package com.gugee.ins.data.collector.comment.listener;

import com.gugee.ins.data.collector.comment.config.InsCommentConfig;
import com.gugee.ins.data.collector.comment.service.InsCommentService;
import com.gugee.ins.data.common.consumer.AbstractGugeeConsumerHandler;
import com.gugee.ins.data.common.msg.InsBloggerMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * InsCommentListener
 *
 * @author XiGua
 */
@Component
@Slf4j
public class InsCommentListener {

    /**
     * InsCommentConfig
     */
    @Autowired
    private InsCommentConfig insCommentConfig;

    /**
     * InsCommentService
     */
    @Autowired
    private InsCommentService insCommentService;

    private InsCommentCollectHandler collectHandler =new InsCommentCollectHandler();

    /**
     * 监听任务,完成评论采集
     * @param messages
     * @param ack
     */
    @KafkaListener(id="${kafka.consumer.group.insCommentCollect.id}",
            topics = {"${kafka.topics.insCommentCollect.online}","${kafka.topics.insCommentCollect.priority}"},
            containerFactory = "factoryInsCommentCollectAck")
    public void bloggerMainCollect(List<InsBloggerMessage> messages, Acknowledgment ack) {
        collectHandler.handle("InsCommentCollect",messages,insCommentConfig.getAcceptInsCommentMsgTimeMinRange(),ack);
    }

    class InsCommentCollectHandler extends AbstractGugeeConsumerHandler<InsBloggerMessage>{
        @Override
        public void dealMsg(List<InsBloggerMessage> messages) {
            insCommentService.handleInsCommentCollect(messages);
        }
    }
}
